<template>
  <BaseForm v-model="formDataModel" @close="$emit('callBack')" />

</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
// import StoreMaterialInfoDetailApi from '/@/api/src/StoreMaterialInfoDetailApi.ts';
// 接口
import StoreMaterialInfoDetailApi from '/@/api/StoreMaterialInfoDetailApi.ts';
import { translate } from "/@/i18n";
import FORM_FIELD_TYPE from "/@/constants/FormFieldType.ts";
defineOptions({
  name: 'StoreMaterialInfoDetailEdit',
})
const props = defineProps({
  modelValue: {

  }
})
const emit = defineEmits(['fetch-data', 'callBack'])

const formRef = ref<FormInstance>();
const title = ref<string>('');
const dialogFormVisible = ref<boolean>(false);
const formDataModel = ref({
  columnCount: 1,
  expandLimit: 6,
  autoFit: false,
  columnWidth: '300px',
  labelPosition: 'right',
  labelWidth: '100px',
  modelData: {},  //表单参数值 初始化
  callback: async (any: object) => {  //表单执行成功后回调
    //完成数据提交
    const { message } = await StoreMaterialInfoDetailApi.save(any)
    $baseMessage(message, 'success', 'vab-hey-message-success');
    dialogFormVisible.value = false


    //事件及数据推送到上一层父类
    emit('callBack', any); //把表单数据推送到上一层
  },
  items: [  //表单item数据初始化
    // {
    //   label: "物料信息ID",
    //   field: "storeMaterialInfoId",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    {
      label: "物料编码",
      field: "materialCode",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",
      config: {
        disabled: true,
      },
      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
    },
    {
      label: "物料名称",
      field: "materialName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      config: {
        disabled: true,
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    // {
    //   label: "物料规格",
    //   field: "materialSpc",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,
    //   config: {
    //     disabled: true,
    //   },
    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "供应商ID",
    //   field: "supplierId",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,
    //   config: {
    //     disabled: true,
    //   },
    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    {
      label: "供应商名称",
      field: "supplierName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      config: {
        disabled: true,
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "检测报告名称",
      field: "testReport",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      config: {
        disabled: true,
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    // {
    //   label: "报告有效期",
    //   field: "reportDate",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,
    //   // config: {
    //   //   disabled: true,
    //   // },
    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    {
      label: "报告有效期",
      field: "reportDate",
      clearable: true,
      type: FORM_FIELD_TYPE.DATE,
      placeholder: "请输入",
      // config: {
      //   limit: 1
      // },
      //         rule: {
      //         required: true,
      //         trigger: 'blur',
      //         message: '宠物主图片不能为空'
      //       },
      rule: [
        {
          // required: true,
          trigger: 'blur',

          validator: (rule: any, value: any, callback: any) => {  //绑定验证
            callback();
          },
        },
        {
          required: true,
          message: '报告有效期不能为空',
        }
      ],

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        }
      },
    },
    {
      label: "检测报告",
      field: "reportUrl",
      clearable: true,
      type: FORM_FIELD_TYPE.UPLOAD,
      config: {
        type: "file",
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },

    // {
    //   label: "",
    //   field: "companyId",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "创建人",
    //   field: "creator",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "修改人",
    //   field: "reviser",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "排序",
    //   field: "sort",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    {
      label: "创建时间",
      field: "create_time",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      config: {
        disabled: true,
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "更新时间",
      field: "update_time",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      config: {
        disabled: true,
      },
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
  ],
})






//页面数据加载
onMounted(async () => {

  //初始化数据model
  if (props.modelValue.query) { //跳转过来时候有参数
    if (props.modelValue.query.storeMaterialInfoDetailId) {  //id存在则为编辑，加载网络数据，如上级页面带参数手动覆盖

      const { data } = await StoreMaterialInfoDetailApi.getDetail({
        storeMaterialInfoDetailId: props.modelValue.query.storeMaterialInfoDetailId   //从路由中获取参数
      })
      formDataModel.value.modelData = data;
    } else {
      //新增时候则用父类页面传参默认填充可根据业务修改
      for (const key in props.modelValue.query) {
        formDataModel.value.modelData[key] = props.modelValue.query[key]
      }
    }
  }
})


//方法暴露区域  todo
defineExpose({

})

</script>
